using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameStateManagementSample
{
    class Tetris
    {
        private static Tetris instance;


        public static Tetris Instance
       {
          get 
          {
             if (instance == null)
             {
                 instance = new Tetris();
             }
             return instance;
          }
       }
        public int[][][,] m_Data;

        private Tetris()
        {
#region Fill Data
            m_Data = new int[7][][,];
            /************************************************************************/
            /* Brick I
             * Type =0
             * Width = 4 
             * Height =4
             * Total status = 2
            /************************************************************************/
            m_Data[0] = new int[2][,];
            int[,] t0 = {
                            { 0, 0, 0, 0},
                            { 1, 1, 1, 1},
                            { 0, 0, 0, 0},
                            { 0, 0, 0, 0}
                        };
            FillData(0, 0, t0, 4, 4);
            int[,] t1 = {
                            { 0, 0, 1, 0},
                            { 0, 0, 1, 0},
                            { 0, 0, 1, 0},
                            { 0, 0, 1, 0}
                        };
            FillData(0, 1, t1, 4, 4);

            /************************************************************************/
            /* Brick L1
             * Type = 1
             * Width = 3
             * Height = 3
             * Total status = 4
            /************************************************************************/
            m_Data[1] = new int[4][,];
            int[,] t10 = {
                            { 0, 1, 0},
                            { 0, 1, 0},
                            { 1, 1, 0}
                        };
            int[,] t11 = {
                            { 0, 0, 0},
                            { 1, 1, 1},
                            { 0, 0, 1}
                        };
            int[,] t12 = {
                            { 0, 1, 1},
                            { 0, 1, 0},
                            { 0, 1, 0}
                        };

            int[,] t13 = {
                            { 1, 0, 0},
                            { 1, 1, 1},
                            { 0, 0, 0}
                        };
            FillData(1, 0, t10, 3, 3);
            FillData(1, 1, t11, 3, 3);
            FillData(1, 2, t12, 3, 3);
            FillData(1, 3, t13, 3, 3);
            /************************************************************************/
            /* Brick L2
             * Type = 2
             * Width = 3
             * Height = 3
             * Total status = 4
            /************************************************************************/
            int[,] t20 = {
                            { 0, 1, 0},
                            { 0, 1, 0},
                            { 0, 1, 1}
                        };
            int[,] t21 = {
                            { 0, 0, 1},
                            { 1, 1, 1},
                            { 0, 0, 0}
                        };
            int[,] t22 = {
                            { 1, 1, 0},
                            { 0, 1, 0},
                            { 0, 1, 0}
                        };

            int[,] t23 = {
                            { 0, 0, 0},
                            { 1, 1, 1},
                            { 1, 0, 0}
                        };
            m_Data[2] = new int[4][,];
            FillData(2, 0, t20, 3, 3);
            FillData(2, 1, t21, 3, 3);
            FillData(2, 2, t22, 3, 3);
            FillData(2, 3, t23, 3, 3);
            /************************************************************************/
            /* Brick O
             * Type = 3
             * Width = 2
             * Height = 2
             * Total status = 1
            /************************************************************************/
            int[,] t30 = {
                            { 1, 1},
                            { 1, 1}
                        };
            m_Data[3] = new int[1][,];
            FillData(3, 0, t30, 2, 2);
            /************************************************************************/
            /* Brick T
             * Type = 4
             * Width = 3
             * Height = 3
             * Total status = 4
            /************************************************************************/
            int[,] t40 = {
                            { 0, 0, 0},
                            { 1, 1, 1},
                            { 0, 1, 0}
                        };
            int[,] t41 = {
                            { 0, 1, 0},
                            { 0, 1, 1},
                            { 0, 1, 0}
                        };
            int[,] t42 = {
                            { 0, 1, 0},
                            { 1, 1, 1},
                            { 0, 0, 0}
                        };

            int[,] t43 = {
                            { 0, 1, 0},
                            { 1, 1, 0},
                            { 0, 1, 0}
                        };
            m_Data[4] = new int[4][,];
            FillData(4, 0, t40, 3, 3);
            FillData(4, 1, t41, 3, 3);
            FillData(4, 2, t42, 3, 3);
            FillData(4, 3, t43, 3, 3);
            /************************************************************************/
            /* Brick Z1
             * Type = 5
             * Width = 3
             * Height = 3
             * Total status = 2
            /************************************************************************/
            int[,] t50 = {
                            { 1, 1, 0},
                            { 0, 1, 1},                            
                            { 0, 0, 0}
                        };
            int[,] t51 = {
                            { 0, 0, 1},
                            { 0, 1, 1},
                            { 0, 1, 0}
                        };
            m_Data[5] = new int[2][,];
            FillData(5, 0, t50, 3, 3);
            FillData(5, 1, t51, 3, 3);
            /************************************************************************/
            /* Brick Z2
             * Type = 6
             * Width = 3
             * Height = 3
             * Total status = 2
            /************************************************************************/
            int[,] t60 = {
                            { 0, 1, 1},
                            { 1, 1, 0},                            
                            { 0, 0, 0}
                        };
            int[,] t61 = {
                            { 1, 0, 0},
                            { 1, 1, 0},
                            { 0, 1, 0}
                        };
            m_Data[6] = new int[2][,];
            FillData(6, 0, t60, 3, 3);
            FillData(6, 1, t61, 3, 3);
#endregion
        }
        public int Size(int _Type)
        {
            int result = 0;
            switch (_Type)
            {
                case 1:
                case 2:
                case 4:
                case 5:
                case 6:
                    result = 3;
                    break; 
                case 3:
                    result = 2;
                    break;
                case 0:
                    result = 4;
                    break;             
                                 
            }
            return result;
        }
        public int TotalStatus(int _Type)
        {
            int result = 1;
            switch (_Type)
            {               
                case 3:
                    result = 1;
                    break;
                case 0:
                case 5:
                case 6:
                    result = 2;
                    break;
                case 1:
                case 2:
                case 4:
                    result = 4;
                    break;
            }
            return result;
        }
        public int[,] Data(int _Type, int _Status)
        {
            return m_Data[_Type][_Status];
        }
        private void FillData (int _Type,int _index,int[,] _Array,int _Width,int _Height)
        {
            m_Data[_Type][_index] = new int[_Width, _Height];
            for (int i = 0; i < _Width; i++)
            {
                for (int j = 0; j < _Height; j++)
                {
                    m_Data[_Type][_index][i, j] = _Array[j, i];
                }
            }
        }

    }
}
